
import { defineStore } from "pinia";
import axios from "axios";
import { nanoid } from "nanoid";
import { reactive } from "vue";
export const useTalkStore = defineStore("loveTalk", () => {
    const talkList = reactive(
        JSON.parse(localStorage.getItem('talkList') as string) || []
    )

    // 函数
    async function getLoveTalk() {
        let {
            data: { content: title },
        } = await axios.get("https://api.uomg.com/api/rand.qinghua?format=json");
        // 把请求回来的字符串，包装成一个对象
        let obj = { id: nanoid(), title };
        // 放到数组中
        talkList.unshift(obj);
    }
    return {
        talkList,
        getLoveTalk
    }
});

